<template>
  <div class="app-container pr">
    <div class="page-left">
      <Approve :get-data="selectNode" :info="info" />
    </div>
    <div class="page-right fl">
      <el-form ref="filter" :model="filter" label-width="0">
        <el-form-item class="mr10 mb5 fl">
          <el-input v-model="filter.name" placeholder="流程名称" size="small" clearable />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl" style="width: 300px">
          <el-button type="primary" size="small" @click="getList()">查 询</el-button>
          <el-button :disabled="filter.dept_id === '' ? true : false" type="primary" size="small" @click="handleAdd()">新 增</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="app.loading" class="search-table" :data="list" border fit highlight-current-row style="width: 100%;">
        <el-table-column label="序号" align="center" width="56px" fixed="left">
          <template slot-scope="{$index}">
            {{ $index + 1 }}
          </template>
        </el-table-column>
        <el-table-column label="名称" width="220px" prop="name" fixed="left"/>
        <el-table-column label="部门" min-width="220px" prop="dept_names" />
        <el-table-column label="抄送" width="220px" prop="nickname" />
        <el-table-column label="状态" align="center" width="80px" prop="state" :formatter="formatter" />
        <el-table-column label="创建日期" align="center" width="150px" prop="create_time" />
        <el-table-column label="操作" align="center" width="90px" fixed="right">
          <template slot-scope="{row}">
            <el-dropdown>
              <el-button type="primary" size="mini">
                操作<i class="el-icon-arrow-down el-icon--right"></i>
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="handleEdit(row)">编 辑</el-dropdown-item>
                <el-dropdown-item @click.native="handleState(row)">{{row.state === 1 ? '禁 用': '启 用'}}</el-dropdown-item>
                <el-dropdown-item @click.native="handleCC(row)">抄 送</el-dropdown-item>
                <el-dropdown-item @click.native="handleProcess(row)">流 程</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="filter.pageAll>0" :total="filter.pageAll" :page.sync="filter.pageCurrent" :limit.sync="filter.pageNumber" @pagination="getList" />
    </div>
    <Dialog ref="dialog" :get-data="getList" :info="dialog" />
    <Info ref="info" :get-data="getList" :info="dialog" />
    <CC ref="cc" :get-data="getList" :info="dialog" />
  </div>
</template>

<script>
import { processes, updProcess } from '@/api/process'
import Pagination from '@/components/Pagination'
import Approve from './components/process/approve'
import Dialog from './components/process/process-dialog'
import Info from './components/process/infos-dialog'
import CC from './components/process/cc-dialog'

export default {
  components: { Pagination, Approve, Dialog, Info, CC },
  inject: ['app'],
  provide() {
    return {
      app: this.app
    }
  },
  data() {
    return {
      list: [],
      info: {},
      dialog: {
        edit: {},
        title: '',
        type: ''
      },
      filter: {
        pageNumber: 10,
        pageCurrent: 1,
        pageAll: 1
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList(e) {
      this.app.loading = true
      processes({
        ...this.filter,
        ...e
      }).then(response => {
        this.list = response.list
        this.filter = response.filter
        this.app.removeLoding()
      }).catch(err => {
        this.$message.error(err.msg)
      })
    },
    handleState(e) {
      let data = {}
      data.id = e.id
      data.state = e.state === 1 ? '0' : '1'
      updProcess(data).then(response => {
        this.getList()
        this.$message.success('编辑成功')
      }).catch(err => {
        this.$message.error(err.msg)
      })
    },
    handleAdd(e) {
      this.dialog.title = '新增信息'
      this.dialog.type = 'add'
      e = {}
      e.approve_key = this.filter.approve_key
      e.dept_ids = ''
      this.app.dialogParam(this.dialog.edit, ['id', 'name', 'approve_key', 'dept_ids'], e)
      this.$refs['dialog'].visible = true
    },
    handleEdit(e) {
      this.dialog.title = '编辑信息'
      this.dialog.type = 'edit'
      this.app.dialogParam(this.dialog.edit, ['id', 'name', 'approve_key', 'dept_ids'], e)
      this.$refs['dialog'].visible = true
    },
    formatter(e) {
      let state = ''
      switch (e.state) {
        case 0:
          state = '禁用'
          break;
        case 1:
          state = '启用'
          break;     
        default:
          break;
      }
      return state
    },
    handleCC(e) {
      this.dialog.title = '流程抄送人员'
      this.dialog.type = 'list'
      let data = {}
      data.lap_id = e.id
      this.app.dialogParam(this.dialog.edit, ['lap_id'], data)
      this.$refs['cc'].visible = true
    },

    handleProcess(e) {
      this.dialog.title = '审批流程'
      this.dialog.type = 'list'
      let data = {}
      data.lap_id = e.id
      this.app.dialogParam(this.dialog.edit, ['lap_id'], data)
      this.$refs['info'].visible = true
    },
    
    
    selectNode(e) {
      this.$set(this.filter, 'approve_key', e)
      this.getList()
    }
  }
}
</script>
<style scoped>
.page-left{
  width: 216px;
  padding: 2px 10px 0 0;
  bottom: 20px;
  top: 20px;
  overflow: hidden;
  position: absolute;
  overflow-y: auto;
  z-index: 9;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.page-left::-webkit-scrollbar {
  display: none;
}
.page-right{
  padding-left: 216px;
  padding-bottom: 20px;
  width: 100%;
}
</style>
